//
// SoapTrace.Net - A soap message monitoring utility. 
//
// Copyright (C) 2005 Matthew Ward
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Matthew Ward (mrward@users.sourceforge.net)


using NUnit.Framework;
using SoapTrace.Core.Formatters;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace SoapTrace.Tests.RichTextBoxFormatting
{
	/// <summary>
	/// Tests the <see cref="RichTextBoxFormatter"/> with a line of 
	/// text containing two colours.
	/// </summary>
	[ TestFixture ]
	public class TwoColoursRichTextBoxTestFixture
	{
		RichTextBox m_RichTextBox;
		FormattedText m_FormattedText;
		Color m_Text1Colour = Color.Red;
		Color m_Text2Colour = Color.Blue;
		
		string m_Text1 = "Foo";
		string m_Text2 = "Bar";
		
		/// <summary>
		/// Initialises each test.
		/// </summary>
		[ SetUp ]
		public void Init( )
		{
			m_FormattedText = new FormattedText( Color.Black );
			m_FormattedText.Append( m_Text1, m_Text1Colour );
			m_FormattedText.Append( m_Text2, m_Text2Colour );

			m_RichTextBox = new RichTextBox( );
			m_RichTextBox.WordWrap = false;
			m_RichTextBox.Multiline = true;
			
			RichTextBoxFormatter.Format( m_RichTextBox, m_FormattedText );
		}
		
		/// <summary>
		/// Check that the text has been added to the rich text box.
		/// </summary>
		[ Test ]
		public void RichTextBoxText( )
		{
			Assert.AreEqual( String.Concat( m_Text1, m_Text2 ), 
			                m_RichTextBox.Text,
			                "Text not added to rich text box." );
		}
		
		/// <summary>
		/// Checks that the first piece of text in the text box has 
		/// the correct colour.
		/// </summary>
		[ Test ]
		public void FirstTextColour( )
		{
			m_RichTextBox.Select( 0, m_Text1.Length );
			
			Assert.AreEqual( m_Text1Colour, m_RichTextBox.SelectionColor, 
			                "Incorrect text colour for first piece of text." );
		}
		
		/// <summary>
		/// Checks that the second piece of text in the text box has 
		/// the correct colour.
		/// </summary>
		[ Test ]
		public void SecondTextColour( )
		{
			m_RichTextBox.Select( m_Text1.Length, m_Text2.Length );
			
			Assert.AreEqual( m_Text2Colour, m_RichTextBox.SelectionColor, 
			                "Incorrect text colour for second piece of text." );
		}
	}
}
